<template>
	<view class="container-white">
		<view>
			<view class="title">在线考试 方便快捷</view>
			<view><image style="width: 100%;height: 375upx;" src="../../static/img/exam.png" /></view>
		</view>
		<view>
			<view class="options flex-box" @click="goExam(4)">
				<image class="icon" src="../../static/icon/mryt.png" />
				<view style="flex: 1;">
					<view style="color: #FF905A;">每日一题</view>
					<view class="tips">每日一题，轻松掌握</view>
				</view>
				<image class="icon-right" src="../../static/icon/icon-right.png" />
			</view>
			<view class="options flex-box" @click="goExam(1)">
				<image class="icon" src="../../static/icon/zsks.png" />
				<view style="flex: 1;">
					<view style="color: #46B7FD;">正式考试</view>
					<view class="tips">是时候展现你的实力了</view>
				</view>
				<image class="icon-right" src="../../static/icon/icon-right.png" />
			</view>
			<view class="options flex-box" @click="goExam(2)">
				<image class="icon" src="../../static/icon/mnks.png" />
				<view style="flex: 1;">
					<view style="color: #FFD056;">模拟考试</view>
					<view class="tips">周而复始，方能达成</view>
				</view>
				<image class="icon-right" src="../../static/icon/icon-right.png" />
			</view>
			<view class="options flex-box" @click="goPractive">
				<image class="icon" src="../../static/icon/bktk.png" />
				<view style="flex: 1;">
					<view style="color: #24CBDF;">专业提升</view>
					<view class="tips">术业有专攻，道义有精论</view>
				</view>
				<image class="icon-right" src="../../static/icon/icon-right.png" />
			</view>
			<view class="options flex-box" @click="goExam(3)">
				<image class="icon" src="../../static/icon/swks.png" />
				<view style="flex: 1;">
					<view style="color: #E23B4F;">三违考试</view>
					<view class="tips">违章重点在这里，多练少违规</view>
				</view>
				<image class="icon-right" src="../../static/icon/icon-right.png" />
			</view>
		</view>
	</view>
</template>

<script>
import { post_md5 } from '../../common/request';
import { setNavTitle } from '../../common/common';
export default {
	data: () => ({
		view: null,
		title: '',
		logo: ''
	}),
	onShow() {
		this.getTitleLogo();
	},
	onPullDownRefresh() {
		this.getTitleLogo();
	},
	// onHide() {
	// 	if (this.view !== null && this.view !== undefined) {
	// 		this.view.close();
	// 		this.view = null
	// 	}
	// },
	// onUnload() {
	// 	if (this.view !== null && this.view !== undefined) {
	// 		this.view.close();
	// 		this.view = null
	// 	}
	// },
	methods: {
		getTitleLogo() {
			// if (this.view !== null && this.view !== undefined) {
			// 	this.view.close();
			// 	this.view = null;
			// }
			// #ifdef APP-PLUS
			post_md5('/sys/tenantsysconfig/appinfo').then(res => {
				let data = JSON.parse(res.data);
				setNavTitle(data.examinationtitle);
				// this.view = setNavLogo(data.logoUrl)
				// this.view.show();
			});
			// #endif
		},
		getSysInfo() {
			const params = {
				type: 2
			};
		},
		goExam(val) {
			if (parseInt(val) === 4) {
				post_md5('/exam-app/daily/answer/list', {
					userId: uni.getStorageSync('userId')
				}).then(res => {
					let data = res.data || [];
					if (data.length > 0 && data.length === 1) {
						post_md5('/exam-app/daily/answer/record', {
							dailyId: data[0].id,
							userId: uni.getStorageSync('userId')
						}).then(res => {
							if (res.data) {
								uni.showToast({
									title: '今日已完成，请明日再来',
									icon: 'none'
								});
							} else {
								uni.navigateTo({
									url: '../topic/daily-topic' + `?examType=4&id=${data[0].id}&length=${data.length}`
								});
							}
						});
					} else {
						uni.reLaunch({
							url: '/pages/exam/exam-list' + `?examType=4`
						});
					}
				});
			} else {
				uni.reLaunch({
					url: '/pages/exam/exam-list' + `?examType=${val}`
				});
			}
		},
		goPractive() {
			uni.navigateTo({
				url: '/pages/exam/practice'
			});
		}
	}
};
</script>

<style>
.tab-bar {
	height: 80upx;
	line-height: 80upx;
	color: #000000;
	font-size: 32upx;
	/* font-weight: bold; */
	width: 100%;
	background: #ffffff;
	position: fixed;
	top: var(--status-bar-height);
	z-index: 999;
	/* border: #000000 1px solid; */
}

.title {
	text-align: center;
	color: #2d2d2d;
	font-size: 44upx;
	font-weight: bold;
	/* margin-top: 80upx;
		margin-bottom: 36upx; */
	position: absolute;
	z-index: 10;
	top: 70upx;
	left: 0;
	right: 0;
	margin: auto;
}

.options {
	flex: 1;
	height: 80upx;
	padding: 42upx;
	box-shadow: 0px 2px 10px 0px rgba(71, 73, 78, 0.2);
	margin: 0 24upx 30upx 24upx;
	font-size: 32upx;
	border-radius: 82upx;
}

.icon {
	width: 80upx;
	height: 80upx;
	margin-right: 30upx;
}

.tips {
	color: #a2a2a2;
	font-size: 24upx;
	margin-top: 10upx;
}

.icon-right {
	width: 18upx;
	height: 32upx;
}
</style>
